/**
 * 本地数据存储 sessionStorage && localStorage方法合并简写
 * @params type local: localStorage   session: sessionStorage
 */
const typeToggle = (type) => {
  return type == 'local' ? window.localStorage : window.sessionStorage
}

export default {

  set: function(key, value, type = 'local') {
    typeToggle(type).setItem(key, value)
  },

  get: function(key, type = 'local') {
    return typeToggle(type).getItem(key)
  },

  remove: function(key, type = 'local') {
    return typeToggle(type).removeItem(key)
  },

  clear: function(type = 'local') {
    typeToggle(type).clear()
  }
}
